// 这里是pinia的配置文件
import {defineStore} from 'pinia'

interface Animal {
  animal_id: number;
  animal_name: string;
  species: string;
  imageUrl: string;
}

export const bookStore = defineStore('book', {
  state: () => ({
    TabIndex: 0,
  }),
})

export const userStore = defineStore('user', {
  state: () => ({
    LoginDialog: false,//用于控制是否展示登录框
    RegisterDialog: false,//用于控制是否展示注册框
    ChangeDialog: false,//用于控制是否展示修改框
    ShowButton: true,//用于控制是否展示登录按钮
    LoginStatus: false,//用于存储登录状态
    TabIndex: 1,//用于用户收藏页面的tab

    UserName: '',
    Avatar: '',
    UserCollection: [] as Animal[]
  }),
  getters: {},
  actions: {
    setLoginDialog(status: boolean) {
      this.LoginDialog = status
    },
    setRegisterDialog(status: boolean) {
      this.RegisterDialog = status
    },
    setChangeDialog(status: boolean) {
      this.ChangeDialog = status
    },
    // 增加忘记密码窗口控制方法

    setUser(name: string, avatar: string) {
      this.UserName = name
      this.Avatar = avatar
    },
    changeLoginStatus(status: boolean) {
      this.LoginStatus = status
    },
    claerUserName() {
      this.UserName = ''
    },
    setUserCollection(collection: Animal[]) {
      this.UserCollection = collection
    },
    logOut() {
      this.LoginStatus = false
      this.UserName = ''
      this.Avatar = ''
      this.UserCollection = []
    }
  },
  persist: true
})
